package com.orderplus.opshop.core.data.response;

import com.orderplus.opshop.common.util.ValueUtil;
import com.orderplus.opshop.core.constants.enums.ResponseCodeConstant;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

/**
 * created by wangzelong 2019/1/9 9:47
 */
@Data
@ToString(callSuper = true)
public class ResponseData<T> implements Serializable {

	/**
	 * 自定义业务状态码
	 */
	private String code;
	/**
	 * "消息"
	 */
	private String msg;
	/**
	 * "数据"
	 */
	private T data;

	public ResponseData(String msg, T data, String code) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public ResponseData(String msg, String code) {
		this.code = code;
		this.msg = msg;
	}

	public ResponseData() {
		this.code = ResponseCodeConstant.SUCCESS.getResponseCode();
		this.msg = ResponseCodeConstant.SUCCESS.getResponseDesc();
	}

	public static ResponseData success() {
		ResponseData baseReturn = new ResponseData();

		baseReturn.code = ResponseCodeConstant.SUCCESS.getResponseCode();
		baseReturn.msg = ResponseCodeConstant.SUCCESS.getResponseDesc();

		return baseReturn;
	}

	public static ResponseData fail() {
		ResponseData baseReturn = new ResponseData();

		baseReturn.code = ResponseCodeConstant.FAILED.getResponseCode();
		baseReturn.msg = ResponseCodeConstant.FAILED.getResponseDesc();

		return baseReturn;
	}

	public static ResponseData fail(String msg) {
		ResponseData baseReturn = new ResponseData();


		baseReturn.code = ResponseCodeConstant.FAILED_OPERATION.getResponseCode();
		baseReturn.msg = msg;

		return baseReturn;
	}


	public static <T> ResponseData<T> success(T data) {
		ResponseData baseReturn = new ResponseData();

		baseReturn.code = ResponseCodeConstant.SUCCESS.getResponseCode();
		baseReturn.msg = ResponseCodeConstant.SUCCESS.getResponseDesc();

		baseReturn.data = data;

		return baseReturn;
	}

}
